package uk.gov.swmprobation.cplitebase;

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class Project {

	//statics
	static final int TYPE_ERROR = 0;
	static final int TYPE_DRAFT = 1;
	static final int TYPE_MINE = 2;
	static final String[] TYPE_NAMES = {"Error","Drafts","Sent"};
	static final int SENT_NOT = 0;
	static final int SENT_GOT_ID = 1;
	static final int SENT_GOT_FLICKR = 2;
	static final int SENT_FINISHED = 3;
	
	//private variables
    int _id;
    String _image_path;
    String _project_name;
    String _project_status;
    String _comment;
    int _project_type;
    int _project_id;
    double _lat;
    double _lng;
    int _updated;
    String _trust;
    //String _flickr_photo_id;
 
    // Empty constructor
    public Project(){
 
    }
    
 // constructor
    public Project(int id, String image_path, String project_name,String project_status,int project_type,int project_id,double lat,double lng,int updated,String comment,String trust){
        this._id = id;
        this._image_path = image_path;
        this._project_name = project_name;
        this._project_status = project_status;
        this._comment = comment;
        this._project_type = project_type;
        this._project_id = project_id;
        this._lat = lat;
        this._lng = lng;
        this._updated = updated;
        this._trust = trust;
        //this._flickr_photo_id = flickr_photo_id;
    }
    
 // constructor
    public Project(int id, String image_path, String project_name,String project_status,int project_type,int project_id,double lat,double lng,int updated,String comment){
        this._id = id;
        this._image_path = image_path;
        this._project_name = project_name;
        this._project_status = project_status;
        this._comment = comment;
        this._project_type = project_type;
        this._project_id = project_id;
        this._lat = lat;
        this._lng = lng;
        this._updated = updated;
        this._trust = "Unknown";
        //this._flickr_photo_id = "";
    }
    
    // constructor
    public Project(String image_path, double lat, double lng){
    	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");
        this._image_path = image_path;
        this._lat = lat;
        this._lng = lng;
        this._project_name = dateFormat.format(new Date());
        this._project_status = "Draft";
        this._comment="";
        this._project_type = TYPE_DRAFT;
        this._updated = Project.SENT_NOT;
        this._trust = "Unknown";
        //this._flickr_photo_id = "";
    }
    
    public void save(){
    	if (this.getId()>0){
    		DatabaseHandler.updateProject(this);
    	} else {
    		DatabaseHandler.addProject(this);
    		this.setId(DatabaseHandler.getHighestId());	
    	}
    }
    
    //ID
    public int getId(){
        return this._id;
    }
    public void setId(int id){
        this._id = id;
    }
    
    //image url
    public String getImagePath(){
        return this._image_path;
    }
    public void setImagePath(String image_path){
        this._image_path = image_path;
    }
    
    //project name
    public String getProjectName(){
        return this._project_name;
    }
    public void setProjectName(String project_name){
        this._project_name = project_name;
    }
    
    //project status
    public String getProjectStatus(){
        return this._project_status;
    }
    public void setProjectStatus(String project_status){
        this._project_status = project_status;
    }
    
    //project type
    public int getProjectType(){
        return this._project_type;
    }
    public void setProjectType(int project_type){
        this._project_type = project_type;
    }
    
    //project id
    public int getProjectId(){
        return this._project_id;
    }
    public void setProjectId(int project_id){
        this._project_id = project_id;
    }
    
    //lat
    public double getLat(){
        return this._lat;
    }
    public void setLat(double lat){
        this._lat = lat;
    }
    
    //lng
    public double getLng(){
        return this._lng;
    }
    public void setLng(double lng){
        this._lng = lng;
    }
    
    //project comment
    public String getProjectComment(){
    	return this._comment;
    }
    public void setProjectComment(String comment){
    	this._comment = comment;
    }
    
    //updated flag
    public int getUpdated(){
        return this._updated;
    }
    public void setUpdated(int updated){
        this._updated = updated;
    }

  //trust
    public String getTrust(){
        return this._trust;
    }
    public void setTrust(String trust){
        this._trust = trust;
    }
    /*
  //trust
    public String getFlickrPhotoId(){
        return this._trust;
    }
    public void setFlickerPhotoId(String flickr_photo_id){
        this._flickr_photo_id = flickr_photo_id;
    }
    */
    @Override
    public String toString(){
    	StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append("ID: " + this._id + NEW_LINE);
        result.append("Image Path: " + this._image_path + NEW_LINE);
        result.append("Project Name: " + this._project_name + NEW_LINE );
        result.append("Project Status: " + this._project_status + NEW_LINE);
        result.append("Project Type: " + this._project_type + NEW_LINE);
        result.append("Project ID: " + this._project_id + NEW_LINE );
        result.append("Lat: " + this._lat + NEW_LINE);
        result.append("Lng: " + this._lng + NEW_LINE);
        result.append("Updated: " + this._updated + NEW_LINE);
        result.append("Trust: " + this._trust + NEW_LINE);
        
        return result.toString();
    }
    
}
